﻿using System.Collections.Generic;
using Model.DBInteractions;
using Model.EntityRepositories;
using Model.Entities;
using Model.Interfaces;

namespace Model.Services
{
    public class ContentService : IContentService
    {
        private readonly IContentRepository _ContentRepository;
        private readonly IUnitOfWork _unitOfWork;
        public ContentService(IContentRepository ContentRepository, IUnitOfWork unitOfWork)
        {
            this._ContentRepository = ContentRepository;
            this._unitOfWork = unitOfWork;
        }  
        #region IContentService Members

        public IEnumerable<Content> GetContents()
        {
            var Contents = _ContentRepository.GetAll();
            return Contents;
        }

        public Content GetContentById(int id)
        {
            var Content = _ContentRepository.GetById(id);
            return Content;
        }

        public void CreateContent(Content Content)
        {
            _ContentRepository.Add(Content);
            _unitOfWork.Commit();
        }

        public void DeleteContent(int id)
        {
            var Content = _ContentRepository.GetById(id);
            _ContentRepository.Delete(Content);
            _unitOfWork.Commit();
        }

        public void UpdateContent(Content Content)
        {
            _ContentRepository.Update(Content);
            _unitOfWork.Commit();
        }

        public void SaveContent()
        {
            _unitOfWork.Commit();
        }

        #endregion
    }
}
